package com.foredu.fiqs.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.foredu.fiqs.domain.EmpPost;
import com.foredu.fiqs.domain.EmpTitle;
import com.foredu.fiqs.domain.EmpType;
import com.foredu.fiqs.domain.Role;
import com.foredu.fiqs.service.IManagementService;
import com.foredu.fiqs.web.actionform.EmpTitleActionForm;
import com.foredu.fiqs.web.actionform.EmpTypeActionForm;
import com.foredu.fiqs.web.actionform.RoleActionForm;

/**
 * 职称管理,职务管理
 * @author Administrator
 *
 */

public class EmpTypeAction extends AbstractBaseDispatchAction {
	private IManagementService managementService = null;

	public IManagementService getManagementService() {
		return managementService;
	}

	public void setManagementService(IManagementService managementService) {
		this.managementService = managementService;
	}
	/**
	 * 职务类型管理
	 */
	public ActionForward typelist(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<EmpType> empTypes = managementService.findempType();
		request.setAttribute("empTypes", empTypes);
		return mapping.findForward("typelist");
	}
	public ActionForward typesave(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		EmpTypeActionForm eaf = (EmpTypeActionForm) form;
		EmpType empType = new EmpType();
		empType.setName(eaf.getName());
		empType.setDescription(eaf.getDescription());
		managementService.saveEmpType(empType);
		List<EmpType> empTypes = managementService.findempType();
		request.setAttribute("empTypes", empTypes);
		return mapping.findForward("typesave");
	}
	
	public ActionForward typedelete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		EmpTypeActionForm eaf = (EmpTypeActionForm) form;
		managementService.deleteEmpTypeById(eaf.getId());
		List<EmpType> empTypes = managementService.findempType();
		request.setAttribute("empTypes", empTypes);
		return mapping.findForward("typedelete");
	}
	
	
	public ActionForward typetoUpdate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		EmpTypeActionForm eaf = (EmpTypeActionForm) form;
		EmpType empType = managementService.findEmpTypeById(eaf.getId());
		request.setAttribute("empType", empType);
		return mapping.findForward("typetoUpdate");
	}
	
	
	public ActionForward typeupdate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		EmpTypeActionForm eaf = (EmpTypeActionForm) form;
		EmpType empType =new EmpType();
		empType=managementService.findEmpTypeById(eaf.getId());
		empType.setName(eaf.getName());
		empType.setDescription(eaf.getDescription());
		managementService.updateEmpType(empType);
		List<EmpType> empTypes = managementService.findempType();
		request.setAttribute("empTypes", empTypes);
		
		return mapping.findForward("typeupdate");
	}
}
